package com.lb.jwitter.action;


 import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.Collection;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.service.TblDKMHDotDKHocVien;
import com.lb.jwitter.service.TblDKMHDotDKHocVienService;
import com.lb.jwitter.service.TblDKMHDotDK;
import com.lb.jwitter.service.TblDKMHDotDKService;

import com.lb.jwitter.service.TblThongTinHocVien;
import com.lb.jwitter.service.TblThongTinHocVienService;

import com.lb.jwitter.service.TblCanBo;
import com.lb.jwitter.service.TblCanBoService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblDKMHDotDKHocVienFormAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private String dataString; 
    public String getDataString() { return dataString; }

    private Collection<TblDKMHDotDKHocVien> tblDKMHDotDKHocViens; 
    public Collection<TblDKMHDotDKHocVien>  getTblDKMHDotDKHocViens() {
         return tblDKMHDotDKHocViens; 
      } 

    private TblDKMHDotDKHocVienService tblDKMHDotDKHocVienService; 

    private List<TblDKMHDotDK> tblDKMHDotDKs; 
    public List<TblDKMHDotDK>  getTblDKMHDotDKs(){ 
              return tblDKMHDotDKs; 
     } 

    private TblDKMHDotDKService tblDKMHDotDKService; 

    private Collection<TblThongTinHocVien> tblThongTinHocViens; 
    public Collection<TblThongTinHocVien>  getTblThongTinHocViens(){ 
              return tblThongTinHocViens; 
     } 

    private TblThongTinHocVienService tblThongTinHocVienService; 

    private Collection<TblCanBo> tblCanBos; 
    public Collection<TblCanBo>  getTblCanBos(){ 
              return tblCanBos; 
     } 

    private TblCanBoService tblCanBoService; 

  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
    { 
        try{ 
      Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_DKMH_DotDK_HocVien", "xem")){ 
        return "noprivilege"; 
    }
tblDKMHDotDKHocVienService = (TblDKMHDotDKHocVienService) context.getBean("tbl_DKMH_DotDK_HocVienClient"); 
         tblDKMHDotDKService = (TblDKMHDotDKService) context.getBean("tbl_DKMH_DotDKClient"); 

        tblThongTinHocVienService = (TblThongTinHocVienService) context.getBean("tbl_ThongTin_HocVienClient"); 

        tblCanBoService = (TblCanBoService) context.getBean("tbl_CanBoClient"); 

       if(pageSize == 0){ 
            pageSize = 20; 
        } 
        if(page == 0){ 
            page =1; 
        } 
        
        List<ConditionReport> cons = new ArrayList<ConditionReport>();
        { 
            ConditionReport con = new ConditionReport(); 
            con.setCol("id"); 
            con.setValue1("desc"); 
            con.setOperator("order"); 
            cons.add(con); 
        } 
        tblDKMHDotDKs = tblDKMHDotDKService.findtblDKMHDotDKByCondition(cons, 20, 1);
        
        cons.clear();

        if(tblDKMHDotDKs != null && tblDKMHDotDKs.size() > 0){ 
            ConditionReport con = new ConditionReport(); 
            con.setCol("dotDKId.id"); 
            con.setValue1(tblDKMHDotDKs.get(0)); 
            con.setOperator("order"); 
            cons.add(con); 
        }
        { 
            ConditionReport con = new ConditionReport(); 
            con.setCol("hocVienId.MSSV"); 
            con.setValue1("asc"); 
            con.setOperator("order"); 
            cons.add(con); 
        }
        
        
        tblDKMHDotDKHocViens =        tblDKMHDotDKHocVienService.findtblDKMHDotDKHocVienByCondition(cons, pageSize, page); 
        
        pages = tblDKMHDotDKHocVienService.counttblDKMHDotDKHocVienByCondition(cons)/pageSize + 1; 
      
      
      dataString = ""; 
      if(tblDKMHDotDKs != null && tblDKMHDotDKs.size() > 0)
          dataString += "&dotDKId=" + tblDKMHDotDKs.get(0).getId(); 
      dataString += "&hoTen=" ; 
      dataString += "&mssv=" ;
      dataString += "&khongDangKyYN=-1"; 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
      System.out.println("Loi Form tbl_DKMH_DotDK_HocVien Action"); 
     e.printStackTrace(); 
    return Action.ERROR; 
 } 
 } 
 } 
 
